package main

import "fmt"

func updateSlice(arr []int)  {
	arr[0] = 25
	printSlice(arr)
}

func printSlice(arr []int) {
	fmt.Printf("execute printSlice() len=%d, cap=%d, arr=%v\n",
		len(arr), cap(arr), arr)
}

// 切片
func main() {
	//arr := [...]int{0, 1, 2, 3, 4}
	arr := []int{0, 1, 2, 3, 4}
	//fmt.Println(arr[0:1])
	//fmt.Println(arr[2:4])
	fmt.Println(arr[:])
	fmt.Println("before updateSlice(arr) <- ", arr)
	updateSlice(arr[:])
	fmt.Println("after updateSlice(arr) <- ", arr)
	s1 := arr[1:3]
	fmt.Println("before updateSlice(s1) <- ", s1)
	updateSlice(s1)
	fmt.Println("after updateSlice(s1) <- ", s1)
	fmt.Println("after updateSlice(arr) <- ", arr)
	s2 := arr[3:4]
	fmt.Println("before updateSlice(s2) <- ", s2)
	updateSlice(s2)
	fmt.Println("after updateSlice(s2) <- ", s2)
	fmt.Println("after updateSlice(arr) <- ", arr)
	// append
	var arr1 []int
	fmt.Println(arr1 == nil)
	printSlice(arr1)
	arr1 = append(arr1, 0, 1, 2)
	printSlice(arr1)
	copyArr := make([]int, len(arr1), cap(arr1))
	copy(copyArr, arr1)
	printSlice(arr1)
	printSlice(copyArr)

}
